package com.deyuanyun.pic.insp.controller.inspresult;

import com.deyuanyun.pic.common.dto.PageJsonBean;
import com.deyuanyun.pic.common.util.RequestUtil;
import com.deyuanyun.pic.common.util.ResponseUtil;
import com.deyuanyun.pic.common.util.ajax.AjaxSupport;
import com.deyuanyun.pic.insp.service.inspresult.ReferenceService;
import com.deyuanyun.pic.insp.util.InspExportUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

/**
 * 内检测参考点信息
 *
 * @author scalpel.王敏
 * @version [v1.0] 创建时间（2016/11/2）
 * @see // 引用的类
 * Method List:
 * 1.----------------
 * 2.----------------
 * History:
 */

@Controller
@RequestMapping("/insp/reference")
public class ReferenceController {


    @Resource
    private ReferenceService referenceService;

    @RequestMapping("/page.html")
    public ModelAndView page()
    {
        return new ModelAndView("insp/inspresult/testPile");
    }


    @RequestMapping("/search.json")
    public void searchMaintainability(@RequestParam HashMap<String,Object> map, HttpServletResponse response){
        ModelAndView mv = new ModelAndView();
        PageJsonBean jsonBean = new PageJsonBean();
        //条件查询 分页列表
        Page main = (Page) referenceService.findPage(map);
        jsonBean.setList(main);
        AjaxSupport.sendSuccessText("",jsonBean);
    }



    @ResponseBody
    @RequestMapping("/export.json")
    public void export(HttpServletRequest request, HttpServletResponse response)
    {


        HashMap param= RequestUtil.parseRequestParamToHashMap(request);
        List result=referenceService.findExport(param);
        param.put("data",result);
        try {
            InspExportUtil.exportExcel(request.getRealPath("/")+"/WEB-INF/classes/template/excl/insp/reference.xlsx",param,response,"参考点");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
